package com.guli.gulimall.member.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.nacos.client.utils.StringUtils;
import com.guli.common.vo.MemberTo;
import com.guli.gulimall.member.vo.ThriendVo;
import com.guli.gulimall.member.vo.WeiboVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.guli.gulimall.member.entity.MemberEntity;
import com.guli.gulimall.member.service.MemberService;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.R;

import javax.servlet.http.HttpSession;


/**
 * 会员
 *
 * @author wzh
 * @email sunlightcs@gmail.com
 * @date 2021-12-09 15:54:46
 */
@RestController
@RequestMapping("member/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    @Autowired
    private HttpSession session;

    @GetMapping("/login")
    public R login(@RequestParam String username,@RequestParam String password) {
        return memberService.login(username,password);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    @GetMapping("/getMemberByToken")
    public MemberEntity getMemberByToken(@RequestParam("token") String token) {
        return memberService.getMemberByToken(token);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public Integer save(@RequestBody MemberEntity member){
		memberService.save(member);

        return 1;
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
